﻿using Dapper;
using isky.dapper;
using isky.logic;
using isky.webapi;
using isky.webapi.DataAccess;
using log4net;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Dynamic;
using System.Linq;
using System.Reflection;
using System.ServiceModel;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Topshelf;


[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
namespace iskytask
{

    public class Program
    {
        static void Main(string[] args)
        {
            ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            try
            {
                //RFMLogic rfm = new RFMLogic();
                //rfm.RFMTiming();
                //Console.WriteLine("end");
                ////IEnumerable<dynamic> accountJson = rfm.ListAccount();
                //// log.Info($"测试：{JsonConvert.SerializeObject(accountJson)}");
                //// Console.WriteLine("end:"+ JsonConvert.SerializeObject(accountJson));
                ////Console.ReadLine();
                ///
                RFMwebapi rFMwebapi = new RFMwebapi();
                RFMRecencySql rFMRecencySql = new RFMRecencySql();
                IEnumerable<dynamic> res= rFMRecencySql.ListAccounttest();


                string cmdText = @" select acc.accountid,acc.creditlimit from  accountbase as acc where  StatusCode = 1";
                SqlBuilder sqlbuilder = new SqlBuilder();
                var sqlTemplate = sqlbuilder.AddTemplate(cmdText);
                using (IDbConnection dbconn = ConnectionFactory.CreateConnection(ConnectionFactory.XRMDBName))
                {
                    IEnumerable<dynamic> result= dbconn.Query(sqlTemplate.RawSql, sqlTemplate.Parameters);
                    foreach (var item in result)
                    {
                        dynamic dyaccount= new ExpandoObject();              
                        dyaccount.creditlimit = item.creditlimit+100000000;
                        rFMwebapi.UpdateAccountInfo(dyaccount, item.accountid);
                    }
                }

            }
            catch (Exception e)
            {
                log.Error(e.StackTrace + e.Message);
            }
            finally
            {

            }
        }



    }
}
